/*
 * EBKlantForm.java
 *
 * Created on 27 mei 2008, 16:51
 */

package energiebedrijf;

import energiebedrijf.Classes.Klant;
import org.jdesktop.application.Action;

/**
 * Laat een klant toevoegen of wijzigen
 * @author  pdb
 */
public class EBKlantForm extends javax.swing.JDialog {
    
    private Klant klant;
    private boolean cancelled;

    /** Deze contructor maakt een nieuw formulier aan met Klant gegevens en 
      * laat deze zien.
      * @param parent Het parent frame
      * @param modal Geeft aan of het formulier modaal of niet is
      * @param klant Het klant object wat ge-edit wordt 
     */
    public EBKlantForm(java.awt.Frame parent, boolean modal, Klant klant) {
        super(parent, modal);
        initComponents();
        this.setLocationRelativeTo(parent);
        
        this.klant = klant;
        txtKlantnaam.setText(this.klant.getKlantNaam());
        txtStraatnaam.setText(this.klant.getStraat());
        txtHuisnummer.setText(this.klant.getHuisnummer());
        txtPostcode.setText(this.klant.getPostcode());
        txtPlaats.setText(this.klant.getPlaats());
        
        if (this.klant.getKlantId() == -1) {
            this.setTitle("Nieuwe klant toevoegen");
        }
        
        this.setVisible(true);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txtKlantnaam = new javax.swing.JTextField();
        txtStraatnaam = new javax.swing.JTextField();
        txtHuisnummer = new javax.swing.JTextField();
        txtPostcode = new javax.swing.JTextField();
        txtPlaats = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        btnCancel = new javax.swing.JButton();
        btnSave = new javax.swing.JButton();

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(energiebedrijf.EnergieBedrijfApp.class).getContext().getResourceMap(EBKlantForm.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setName("Form"); // NOI18N
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel1.setName("jPanel1"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        txtKlantnaam.setText(resourceMap.getString("txtKlantnaam.text")); // NOI18N
        txtKlantnaam.setName("txtKlantnaam"); // NOI18N

        txtStraatnaam.setText(resourceMap.getString("txtStraatnaam.text")); // NOI18N
        txtStraatnaam.setName("txtStraatnaam"); // NOI18N

        txtHuisnummer.setText(resourceMap.getString("txtHuisnummer.text")); // NOI18N
        txtHuisnummer.setName("txtHuisnummer"); // NOI18N

        txtPostcode.setText(resourceMap.getString("txtPostcode.text")); // NOI18N
        txtPostcode.setName("txtPostcode"); // NOI18N

        txtPlaats.setText(resourceMap.getString("txtPlaats.text")); // NOI18N
        txtPlaats.setName("txtPlaats"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtStraatnaam, javax.swing.GroupLayout.DEFAULT_SIZE, 271, Short.MAX_VALUE)
                    .addComponent(txtKlantnaam, javax.swing.GroupLayout.DEFAULT_SIZE, 271, Short.MAX_VALUE)
                    .addComponent(txtHuisnummer, javax.swing.GroupLayout.DEFAULT_SIZE, 271, Short.MAX_VALUE)
                    .addComponent(txtPostcode, javax.swing.GroupLayout.DEFAULT_SIZE, 271, Short.MAX_VALUE)
                    .addComponent(txtPlaats, javax.swing.GroupLayout.DEFAULT_SIZE, 271, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtKlantnaam, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtStraatnaam, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtHuisnummer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtPostcode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtPlaats, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(energiebedrijf.EnergieBedrijfApp.class).getContext().getActionMap(EBKlantForm.class, this);
        btnCancel.setAction(actionMap.get("btnCancel_Click")); // NOI18N
        btnCancel.setText(resourceMap.getString("btnCancel.text")); // NOI18N
        btnCancel.setName("btnCancel"); // NOI18N

        btnSave.setAction(actionMap.get("btnSave_Click")); // NOI18N
        btnSave.setText(resourceMap.getString("btnSave.text")); // NOI18N
        btnSave.setName("btnSave"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(212, Short.MAX_VALUE)
                .addComponent(btnSave, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnCancel)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnCancel)
                    .addComponent(btnSave))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
// TODO add your handling code here:
    
}//GEN-LAST:event_formWindowClosing

    /** Deze action wordt uitgevoerd als op de Annuleren knop geklikt wordt */
    @Action
    public void btnCancel_Click() {
        this.cancelled = true;
        this.setVisible(false);
    }

    /** Deze action wordt uitgevoerd als op de Opslaan knop geklikt wordt */
    @Action
    public void btnSave_Click() {
        this.cancelled = false;
        GetChanges();
        this.setVisible(false);
    }
    
    /** Geeft aan of het formulier geannuleerd is of niet, als de waarde true 
     *  dan is het formulier geannuleerd anders niet
     */
    public boolean getCancelled() {
        return this.cancelled;
    }
    
    /** Deze method slaat de wijzigingen op in het klant object */
    private void GetChanges() {
        this.klant.setKlantNaam(txtKlantnaam.getText());
        this.klant.setStraat(txtStraatnaam.getText());
        this.klant.setHuisnummer(txtHuisnummer.getText());
        this.klant.setPostcode(txtPostcode.getText());
        this.klant.setPlaats(txtPlaats.getText());
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancel;
    private javax.swing.JButton btnSave;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField txtHuisnummer;
    private javax.swing.JTextField txtKlantnaam;
    private javax.swing.JTextField txtPlaats;
    private javax.swing.JTextField txtPostcode;
    private javax.swing.JTextField txtStraatnaam;
    // End of variables declaration//GEN-END:variables

}
